/**
 * 26. Remove Duplicates from Sorted Array
 * https://leetcode.com/problems/remove-duplicates-from-sorted-array/
 */
package lc26;

public class Main {
  public static void main(String[] args) {
    int[] nums = {0,0,1,1,1,2,2,3,3,4};
    int len = new Solution().removeDuplicates(nums);
    System.out.println(len);
    for (int i = 0; i < len; i++) {
      System.out.print(nums[i] + " ");
    }
  }
}

class Solution {
  public int removeDuplicates(int[] nums) {
    int cursor = 0;
    for (int i = 1; i < nums.length; i++) {
      if (nums[i] == nums[cursor]) {
        continue;
      }
      nums[++cursor] = nums[i];
    }
    return cursor + 1;
  }
}
